/**
 * 首页警示管理
 */
Ext.define('Module.wg.WgSyjs', {
	extend : 'Ext.panel.Panel',
	alias : 'widget.wgSyjs',
	layout: 'border',
	initComponent : function() {
		var me = this;
		var store=Ext.create('Ext.data.Store',{
			autoLoad: true,
			fields: ['id','title','zcvideoId','wgvideoId','zcnr','wgnr','upuser','uptime','zcvName','wgvName'],
	        proxy: {
	            type: 'ajax',
	            url: 'wgSyjsAction/getWgSyjs.do',
	            reader: {
					root: 'datas',
					totalProperty: 'total'
				}
	        }
		});
		
		
		var wgSyjsPanel = me.wgSyjsPanel = Ext.create('Ext.grid.Panel',{
			title: '首页警示视频列表',
			region: 'center',
			padding: '0 1 0 0',
//			width: 650,
			store: store,
			tbar:[{
				xtype: 'panel',
				border: false,
				height: 25,
				width: '100%',
				bodyPadding: 0-1,
				layout: 'column',
				defaults: {columnWidth: 1,bodyPadding: 0},
				items: [{
						xtype: 'toolbar',
						items: [{
							text: '添加信息',
							iconCls: 'icon-add',
							handler: function(){
								me.addWgSyjs();
							}
						},{
							text: '修改信息',
							iconCls: 'icon-edit',
							handler: function(){
								var rec = wgSyjsPanel.getSelectionModel().getSelection()[0];
								if(rec){
									me.updateWgSyjs(rec);
								}
								else{
									Ext.Msg.alert('提示', '请选择要修改的信息！');
								}
							}
						},{
							text: '删除信息',
							iconCls: 'icon-delete',
							handler: function(){
								var rec = wgSyjsPanel.getSelectionModel().getSelection()[0];
								if(rec){
									me.delWgSyjs(rec);
								}
								else{
									Ext.Msg.alert('提示', '请选择要删除的信息！');
								}
							}
						},{
							xtype:"textfield",
							fieldLabel : '正常视频名称',	
							maxLength:40,
							labelWidth:90,
							width:220
						},{	
							xtype:"textfield",
							fieldLabel : '违规视频名称',	
							maxLength:40,
							labelWidth:90,
							width:220
						},{
							text:"查询",
							iconCls: 'icon-search',
							handler: function(){
								var tbar = this.up('toolbar');
								var items = tbar.items.items;
								wgSyjsPanel.store.proxy.extraParams = {
									zcvName: items[3].getSubmitValue(),
									wgvName: items[4].getSubmitValue()
								};
								wgSyjsPanel.store.loadPage(1);
							}
						}
					]
				 }]
			}],		
			bbar: Ext.create('Ext.PagingToolbar', {
	            store: store,
	            id: me.id+'-bbar',
	            displayInfo: true,
	            displayMsg: '显示第 {0} 至 {1} 条记录，共 {2} 条',
	            emptyMsg: "无记录"
	        }),
			columns: [{
	            text: '标题',
	            flex: 2.5,
	            dataIndex: 'title'
			},{
	            text: '正常视频名称',
	            flex: 2,
	            dataIndex: 'zcvName'
			},{
	            text: '违规视频名称',
	            flex: 2,
	            dataIndex: 'wgvName'
			},{
	            text: '正常内容',
	            flex: 2.6,
	            dataIndex: 'zcnr'
			},{
	            text: '违规内容',
	            flex: 2.6,
	            dataIndex: 'wgnr'
			}]
		});
		
		
		me.items = [wgSyjsPanel];
		
		me.callParent();
	},
	updateWgSyjs: function(rec){
		var me = this;
		Ext.create('Ext.window.Window',{
			width: 400,
			height: 310,
			iconCls: 'icon-edit',
			modal: true,
			layout: 'fit',
			title: '修改信息',
			buttons: [{
				text: '保存',
				handler: function(){
					var formp = this.up('panel').items.items[0];
        	    	var form = formp.getForm();
        	    	if(form.isValid()){
        	    		form.submit({
            	    	    url: 'wgSyjsAction/updateWgSyjs.do',
            	    	    success: function(form, action) {
            	    	    	var rs = Ext.decode(action.response.responseText);
            	    	    	if(rs.rst){
            	    	    		Ext.Msg.alert('提示', '修改成功！');
            	    	    		formp.up('window').close();
            	    	    		me.wgSyjsPanel.store.load();
            	    	    	}
            	    	    	else{
            	    	    		Ext.Msg.alert('提示', '修改失败！详情：<br>'+rs.msg);
            	    	    	}
            	    	    }
            	    	});
        	    	}
        	    	else{
        	    		Ext.Msg.alert('提示', '无效的信息,请正确填写信息！');
        	    	}
				}
			},{
				text: '取消',
				handler: function(){
					this.up('window').close();
				}
			}],
			items: me.getForm({
				bodyPadding: 10,
				border: false,
				listeners: {
					afterrender: function(fp){
						fp.loadRecord(rec||{});
					}
				}
			})
		}).show();
	},
	addWgSyjs: function(rec){
		var me = this;
		Ext.create('Ext.window.Window',{
			width: 400,
			height: 310,
			iconCls: 'icon-add',
			modal: true,
			layout: 'fit',
			title: '添加信息',
			buttons: [{
				text: '保存',
				handler: function(){
					var formp = this.up('panel').items.items[0];
        	    	var form = formp.getForm();
        	    	if(form.isValid()){
        	    		form.submit({
            	    	    url: 'wgSyjsAction/addWgSyjs.do',
            	    	    success: function(form, action) {
            	    	    	var rs = Ext.decode(action.response.responseText);
            	    	    	if(rs.rst){
            	    	    		Ext.Msg.alert('提示', '保存成功！');
            	    	    		formp.up('window').close();
            	    	    		me.wgSyjsPanel.store.load();
            	    	    	}
            	    	    	else{
            	    	    		Ext.Msg.alert('提示', '保存失败！详情：<br>'+rs.msg);
            	    	    	}
            	    	    }
            	    	});
        	    	}
        	    	else{
        	    		Ext.Msg.alert('提示', '无效的信息,请正确填写信息！');
        	    	}
				}
			},{
				text: '取消',
				handler: function(){
					this.up('window').close();
				}
			}],
			items: me.getForm({
				bodyPadding: 20,
				border: false,
				listeners: {
					afterrender: function(fp){
						fp.loadRecord(rec||{});
					}
				}
			})
		}).show();
	},
	delWgSyjs: function(rec){
		var me = this;
		if(rec){
			Ext.Msg.confirm('提示', '你确定要删除当前信息吗？',function(b){
				if('yes' == b){
					Ext.Ajax.request({
					    url: 'wgSyjsAction/deleteWgSyjs.do',
					    params: rec.data,
					    success: function(response){
        	    	    	var rs = Ext.decode(response.responseText);
        	    	    	if(rs.rst){
        	    	    		Ext.Msg.alert('提示', '删除成功！');
        	    	    		me.wgSyjsPanel.store.load();
        	    	    	}
        	    	    	else{
        	    	    		Ext.Msg.alert('提示', '删除失败！详情：<br>'+rs.msg);
        	    	    	}
					    }
					});
				}
			});
		}
		else{
			Ext.Msg.alert('提示', '请选择要删除的信息！');
		}
	},
	getForm: function(config,readOnly){
		var me=this;
		return Ext.apply({
			xtype: 'form',
			bodyPadding: 10,
			defaults: {anchor: '100%'},
			items: [{
					name: 'id',
					xtype: 'hidden'
				},{
					name: 'zcvideoId',
					id:me.id+'zcvideoId',
					xtype: 'hidden'
				},{
					name: 'wgvideoId',
					id:me.id+'wgvideoId',
					xtype: 'hidden'
				},{
					fieldLabel: '标题',
					name: 'title',
					maxLength:30,
					allowBlank: false,
					xtype: 'textfield'
				},{
					fieldLabel: '正常视频',
					name:'zcvName',
					id:me.id+'zcvName',
					xtype: 'textfield',
					allowBlank: false,
					listeners: {   
						focus: function(p) {   
							me.showVideoListWin();
						}
					}
				},{
					fieldLabel: '违规视频',
					name:'wgvName',
					id:me.id+'wgvName',
					xtype: 'textfield',
					allowBlank: false,
					listeners: {   
						focus: function(p) {   
							me.showWgVideoListWin();
						}
					}
				},{
					xtype: 'textarea',
					fieldLabel: '正常内容',
					name: 'zcnr',
					maxLength:200,
					allowBlank: false
				},{
					xtype: 'textarea',
					fieldLabel: '违规内容',
					name: 'wgnr',
					maxLength:200,
					allowBlank: false
				}
			]
		},config);
	},
	/**
	 * 正常视频窗体列表数据
	 */
	showVideoListWin : function(){
		var me = this;
		var upwindow = Ext.create("Ext.window.Window",{
			layout:'border',
			width:700,
			height:400,
			iconCls:'icon-cog_edit',
			modal:true,
			title:'正常视频',
			buttons:[{
				text:'保存',
				handler:function(){
					var rec = Ext.getCmp(me.id+'videoSynList').getSelectionModel(me.id+'videoSynList').getSelection()[0];
					if(rec){
						Ext.getCmp(me.id+'zcvName').setValue(rec.data.name);
						Ext.getCmp(me.id+'zcvideoId').setValue(rec.data.id);
						upwindow.close();
					}
					else{
						Ext.Msg.alert('提示', '请选择视频的信息！');
					}
				}
			},{
				text:'关闭',
				handler:function(){
					upwindow.close();
				}
			}],
			items:[{
				region: 'center',
				xtype:'grid',
				id:me.id+'videoSynList',
				selModel: Ext.create('Ext.selection.CheckboxModel',{
					mode:'SINGLE'
				}),
				tbar:[{
					labelWidth:65,
					fieldLabel: '视频名称',
					xtype:'textfield'
				},{
					fieldLabel:'同步时间',
					xtype: 'datefield',
					labelWidth: 65,
					width: 170,
					format:'Y-m-d',
					submitFormat: 'Y-m-d'
				},{
					fieldLabel:'至',
					xtype: 'datefield',
					labelWidth: 20,
					width: 125,
					format:'Y-m-d',
					submitFormat: 'Y-m-d'
				},{
					text:'查询',
					width: 55,
					iconCls: 'icon-search',
					handler:function(){
						var xgrid = this.up('window').down('grid');
						xgrid.store.proxy.extraParams = {
								name: xgrid.down('field[fieldLabel=视频名称]').getSubmitValue(),
								startTime: xgrid.down('field[fieldLabel=同步时间]').getSubmitValue(),
								endTime: xgrid.down('field[fieldLabel=至]').getSubmitValue()
						};
						xgrid.store.load();
					}
				}],
				columns:[{
					text:'视频名称',dataIndex:'name',width:200
				},{
					text:'原始路径',dataIndex:'rawpath',width:200
				},{
					text:'同步时间',dataIndex:'syntime',width:130,renderer: formatDate
				}], 
	        	store:Ext.create('Ext.data.Store',{
					autoLoad: true,
					fields:['name','rawpath','syntime'],
					proxy:{
						type:'ajax',
						url:'wgSyjsAction/getVideoSynList.do'
					}
	        	})
			}]
		}).show();
	},
	/**
	 * 违规视频窗体列表数据
	 */
	showWgVideoListWin : function() {
		var me = this;
		var upwindow = Ext.create("Ext.window.Window",{
			layout:'border',
			width:700,
			height:400,
			iconCls:'icon-cog_edit',
			modal:true,
			title:'违规视频',
			buttons:[{
				text:'保存',
				handler:function(){
					var rec = Ext.getCmp(me.id+'videoSynList').getSelectionModel(me.id+'videoSynList').getSelection()[0];
					if(rec){
						Ext.getCmp(me.id+'wgvName').setValue(rec.data.vname);
						Ext.getCmp(me.id+'wgvideoId').setValue(rec.data.videoId);
						upwindow.close();
					}
					else{
						Ext.Msg.alert('提示', '请选择视频的信息！');
					}
				}
			},{
				text:'关闭',
				handler:function(){
					upwindow.close();
				}
			}],
			items:[{
				region: 'center',
				xtype:'grid',
				id:me.id+'videoSynList',
				selModel: Ext.create('Ext.selection.CheckboxModel',{
					mode:'SINGLE'
				}),
				tbar:[{
					xtype:"textfield",
					fieldLabel : '任务内容',	
					labelWidth:60,
					width:200
				},{
					xtype:"textfield",
					fieldLabel : '视频名称',	
					labelWidth:60,
					width:200
				},{
	        		iconCls: 'icon-search',
					text: '查询',
					handler: function(){
						
						var xgrid = this.up('window').down('grid');
						xgrid.store.proxy.extraParams = {
								content: xgrid.down('field[fieldLabel=任务内容]').getSubmitValue(),
								vname: xgrid.down('field[fieldLabel=视频名称]').getSubmitValue()
						};
						xgrid.store.load();
					}
				}],
				columns:[{
					text:'任务内容',dataIndex:'content',width:200
				},{
					text:'视频名称',dataIndex:'vname',width:200
				},{
					text:'标记数量',dataIndex:'bjNumber',width:130
				}], 
	        	store:Ext.create('Ext.data.Store',{
	    			autoLoad: true,
	    			fields: ['videoId','content','vname','userName','bjNumber'],			
	    			proxy: {
	    				type: 'ajax',
	    				url: 'wgSyjsAction/getWgVideoList.do'
	    			}
	    		})
			}]
		}).show();
	}
});